package com.zonekey.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @description:
 * @author: 靳俊英
 * @create: 2021-05-20 10:02
 **/
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        HashMap<String, User> userMap = new HashMap<>(16);
        ArrayList<SimpleGrantedAuthority> authorityArrayList = new ArrayList<>();
        authorityArrayList.add(new SimpleGrantedAuthority("admin"));
        userMap.put("jjy",new User("jjy",passwordEncoder.encode("123456"),authorityArrayList));
        userMap.put("jjy1",new User("jjy1",passwordEncoder.encode("123456"),authorityArrayList));
        return userMap.get(username);
    }
}
